﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Model;

namespace LaKuaShop_TestDemo
{
    /// <summary>
    /// MyReceive.xaml 的交互逻辑
    /// </summary>
    public partial class MyReceive : Window
    {
        public MyReceive()
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            InitializeComponent();
            SuccessMsg.IsActive = false;
            BLL.User User = new BLL.User();
            UserInfo user = User.ShowUserInfo(Common.User.account);
            UserInfo contact = new UserInfo(user.account, user.name, user.tel, user.address);
            this.DataContext = contact;
        }
        //关闭按钮
        private void Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        //保存按钮
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            ErrorMsg.IsActive = false;
            SuccessMsg.IsActive = false;
            SysErrorMsg.IsActive = false;
            TelErrorMsg.IsActive = false;
            string name = TextBoxName.Text;
            string tel = Tel.Text;
            string address = Address.Text;
            Regex regex = new Regex("^13\\d{9}$");
            if (name == "" || tel == "" || address == "")
            {
                ErrorMsg.IsActive = true;
                return;
            }
            else if (!regex.IsMatch(tel))
            {
                TelErrorMsg.IsActive = true;
                return;
            }
            BLL.User User = new BLL.User();
            UserInfo user = new UserInfo(Common.User.account, name, tel, address);
            if (User.UpdateUserAddr(user, Common.User.account) == -1)
            {
                SysErrorMsg.IsActive = true;
                return;
            }
            Common.User.name = name;
            Common.User.tel = tel;
            Common.User.address = address;
            SuccessMsg.IsActive = true;
        }
    }
}
